from django.contrib import admin
from django.utils.html import format_html

from .models import Search


# Register your models here.

class SearchAdmin(admin.ModelAdmin):
    list_display = ('address', 'create_at', 'update_at', 'edit_button', 'delete_button')
    list_filter = ('address',)
    list_per_page = 10
    actions = ['map']

    def map(self, request, queryset):
        pass

    map.short_description = "地图"
    map.type = 'primary'
    # board.style = 'color:blue;'
    map.icon = 'el-icon-view'
    map.confirm = '确定要进入地图吗？'
    map.action_type = 1
    map.action_url = '../map/map/'  # 地图路由地址

    def edit_button(self, obj):
        return format_html(
            f'<a  class= "el-button el-button--primary el-button--small el-icon-edit" '
            f'onclick="href=\'/admin/map/search/{obj.id}/change/\'">编辑</a>')

    edit_button.allow_tags = True
    edit_button.short_description = '编辑'

    def delete_button(self, obj):
        return format_html(
            f'<a  class = "el-button stop-submit el-button--danger el-button--small el-icon-delete" '
            f'onclick="href=\'/admin/map/search/{obj.id}/delete/\'">删除</a>')

    delete_button.allow_tags = True
    delete_button.short_description = '删除'


admin.site.register(Search, SearchAdmin)
